package com.nelson.musicplayer.source

/**
 * @author nelson
 * @since 2020-07-27
 */
data class Resource<out T>(val status: Status, val msg: String, val data: T?, val throwable: Throwable? = null) {
    companion object {
        fun <T> loading(data: T? = null, msg: String = ""): Resource<T> {
            return Resource(Status.LOADING, msg, data)
        }

        fun <T> success(data: T, msg: String = ""): Resource<T> {
            return Resource(Status.SUCCESS, msg, data)
        }

        fun <T> error(data: T? = null, msg: String = "", throwable: Throwable?): Resource<T> {
            return Resource(Status.ERROR, msg, data, throwable)
        }
    }
}

